<script>
	//表格查询  
	function reloadTransOrder() {
		//先取得 datagrid 的查询参数  
		var params = transWebsiteReport_list.datagrid('options').queryParams; 
		printLog(params);
		//设置好查询参数 reload 一下就可以了
		transWebsiteReport_list.datagrid('reload'); 
		transWebsiteReport_list.datagrid('unselectAll');
		transWebsiteReport_list.datagrid('uncheckAll');
	}

	function exportWebReport() {
		//下载代码文件
		if($('#downloadForm')) $('#downloadForm').remove();
		var downloadForm  = $("<form id=\"downloadForm\">");//定义一个form表单
		downloadForm.attr("style","display:none");
		downloadForm.attr("target","");
		downloadForm.attr("method","post");
		printLog($("#transWebsiteReportSearchForm").serialize());
		downloadForm.attr("action",'transReport.do?export&timestamp='+new Date().getTime()+"&"+$("#transWebsiteReportSearchForm").serialize());
		var input1=$("<input>");
		input1.attr("type","hidden");
		input1.attr("name","downLoadCode");
		input1.attr("value",(new Date()).getMilliseconds()); 
		$("body").append(downloadForm);//将表单放置在web中
		downloadForm.append(input1);
		downloadForm.submit();//表单提交
		return false;	
	}
	
	function clearTransOrderSearch() {
		setGridSearchParams('transWebsiteReport_list','transWebsiteReportSearchForm',true,reloadTransOrder);
	}
	
	//根据条件查询
	function transWebsiteReportSearch() {
// 		showWeekFirstDay();
// 		var v = $('#createTimeStart').datetimebox('getValue');		// get datetimebox value
// 		printLog(v);
// 		$('#createTimeStart').datetimebox({
// 		    value: '2016-02-03 22:49:17',
// 		    required: true,
// 		    showSeconds: false
// 		});
		setGridSearchParams('transWebsiteReport_list','transWebsiteReportSearchForm',false,reloadTransOrder);
	}
	
	
	/**   
	* 获取本周、本季度、本月、上月的开端日期、停止日期   
	*/   
	var now = new Date(); //当前日期   
	var nowDayOfWeek = now.getDay(); //今天本周的第几天   
	var nowDay = now.getDate(); //当前日   
	var nowMonth = now.getMonth(); //当前月   
	var nowYear = now.getYear(); //当前年   
	nowYear += (nowYear < 2000) ? 1900 : 0; //  
	  
	var lastMonthDate = new Date(); //上月日期   
	lastMonthDate.setDate(1);   
	lastMonthDate.setMonth(lastMonthDate.getMonth()-1);   
	var lastYear = lastMonthDate.getYear();   
	var lastMonth = lastMonthDate.getMonth();  
	  
	//格局化日期：yyyy-MM-dd   
	function formatDate(date) {   
	var myyear = date.getFullYear();   
	var mymonth = date.getMonth()+1;   
	var myweekday = date.getDate();  
	  
	if(mymonth < 10){   
	mymonth = "0" + mymonth;   
	}   
	if(myweekday < 10){   
	myweekday = "0" + myweekday;   
	}   
	return (myyear+"-"+mymonth + "-" + myweekday);   
	}  
	  
	//获得某月的天数   
	function getMonthDays(myMonth){   
	var monthStartDate = new Date(nowYear, myMonth, 1);   
	var monthEndDate = new Date(nowYear, myMonth + 1, 1);   
	var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);   
	return days;   
	}  
	  
	//获得本季度的开端月份   
	function getQuarterStartMonth(){   
	var quarterStartMonth = 0;   
	if(nowMonth<3){   
	quarterStartMonth = 0;   
	}   
	if(2<nowMonth && nowMonth<6){   
	quarterStartMonth = 3;   
	}   
	if(5<nowMonth && nowMonth<9){   
	quarterStartMonth = 6;   
	}   
	if(nowMonth>8){   
	quarterStartMonth = 9;   
	}   
	return quarterStartMonth;   
	}  
	  
	//获得本周的开端日期   
	function getWeekStartDate() {   
	var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);   
	return weekStartDate;//formatDate(weekStartDate);   
	}  
	  
	//获得本周的停止日期   
	function getWeekEndDate() {   
	var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));   
	return weekEndDate;//formatDate(weekEndDate);   
	}  
	  
	//获得本月的开端日期   
	function getMonthStartDate(){   
	var monthStartDate = new Date(nowYear, nowMonth, 1);   
	return formatDate(monthStartDate);   
	}  
	  
	//获得本月的停止日期   
	function getMonthEndDate(){   
	var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));   
	return formatDate(monthEndDate);   
	}  
	  
	//获得上月开端时候   
	function getLastMonthStartDate(){   
	var lastMonthStartDate = new Date(nowYear, lastMonth, 1);   
	return formatDate(lastMonthStartDate);   
	}  
	  
	//获得上月停止时候   
	function getLastMonthEndDate(){   
	var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));   
	return formatDate(lastMonthEndDate);   
	}  
	  
	//获得本季度的开端日期   
	function getQuarterStartDate(){  
	  
	var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);   
	return formatDate(quarterStartDate);   
	}  
	  
	//或的本季度的停止日期   
	function getQuarterEndDate(){   
	var quarterEndMonth = getQuarterStartMonth() + 2;   
	var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));   
	return formatDate(quarterStartDate);   
	} 
	
	function showMonthFirstDay()
	{
		var date=new Date();
		date.setDate(1);
		date.setHours(0);
		date.setMinutes(0);
		date.setSeconds(0);
		return date;
	}
	function showMonthLastDay()
	{
		var date=new Date();
		var currentMonth=date.getMonth();
	    var nextMonth=++currentMonth;
		var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
		var oneDay=1000*60*60*24;
		var tempDate = new Date(nextMonthFirstDay-oneDay);
		tempDate.setHours(23);
		tempDate.setMinutes(59);
		tempDate.setSeconds(59);
		return tempDate;
	}
	
	function formatterDate(date) {
		var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
		var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
		+ (date.getMonth() + 1);
		var hours = date.getHours();       //获取当前小时数(0-23)
		var minutes = date.getMinutes();     //获取当前分钟数(0-59)
		var seconds = date.getSeconds();     //获取当前秒数(0-59)
		return date.getFullYear() + '-' + month + '-' + day+' '+hours+':'+minutes+':'+seconds;
	}
	
	
	$(document).ready(function() {
		$("#todayRadio").change(function() {
			var todayValue = $("input[id='todayRadio']:checked").val();
			printLog('todayValue='+todayValue);
			if(todayValue) {
				$('#weekRadio').attr('checked', false);
				$('#monthRadio').attr('checked', false);
				var date = new Date();
				date.setHours(0);
				date.setMinutes(0);
				date.setSeconds(0);
				$('#createTimeStart').datetimebox('setValue', formatterDate(date));
				date.setHours(23);
				date.setMinutes(59);
				date.setSeconds(59);
				$('#createTimeEnd').datetimebox('setValue', formatterDate(date));
			}
		});
		
		$("#weekRadio").change(function() {
			var weekValue = $("input[id='weekRadio']:checked").val();
			printLog('weekValue='+weekValue);
			if(weekValue) {
				$('#todayRadio').attr('checked', false);
				$('#monthRadio').attr('checked', false);
				var date = getWeekStartDate();
				date.setHours(0);
				date.setMinutes(0);
				date.setSeconds(0);
				$('#createTimeStart').datetimebox('setValue', formatterDate(date));
				date = getWeekEndDate();
				date.setHours(23);
				date.setMinutes(59);
				date.setSeconds(59);
				$('#createTimeEnd').datetimebox('setValue', formatterDate(date));
			}
		});
		
		$("#monthRadio").change(function() {
			var monthValue = $("input[id='monthRadio']:checked").val();
			printLog('monthValue='+monthValue);
			if(monthValue) {
				$('#todayRadio').attr('checked', false);
				$('#weekRadio').attr('checked', false);
				$('#createTimeStart').datetimebox('setValue', formatterDate(showMonthFirstDay()));
				$('#createTimeEnd').datetimebox('setValue', formatterDate(showMonthLastDay()));
			}
		});
	});
</script>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<@eu.datagrid id="transWebsiteReport_list" toolbar="#transWebsiteReportlist_search" idField="websiteId" operations="${operations!}"
			 url="transReport.do?loadList&creator=${(user.loginName)!}" rownumbers="true" pagination="false"
			 item="com.xdtech.trans.vo.TransWebsiteReport"/>
		
		<div id="transWebsiteReportlist_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="transWebsiteReportSearchForm">
					<table>
						<tr>
							<td width="200">
								<input id="todayRadio" type="radio" value="today" />当天
								<input id="weekRadio" type="radio" value="week" />本周
								<input id="monthRadio" type="radio" value="month" />本月
							</td>
							<td class="tbLabel">创建时间从：</td>
							<td>
								<input id="createTimeStart" name="createTimeStart"  class="easyui-datetimebox" style="width: 158px"/>
							</td>
							<td class="tbLabel">创建时间到：</td>
							<td>
								<input id="createTimeEnd" name="createTimeEnd"  class="easyui-datetimebox" style="width: 158px"/>
							</td>
							<td>
								<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="transWebsiteReportSearch()"/>
	 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearTransOrderSearch()"/>
 					 		</td>
						</tr>
					</table>
				</form>
				
			</div>
			<div id="transWebsiteReport_toolbar" style="height: auto">
				<@eu.linkbutton showName="导出报表" shiro="trans:transWebsiteReport:export" iconCls="icon-export" onclick="exportWebReport()"/>
				<@eu.linkbutton showName="刷新" shiro="trans:transWebsiteReport:refresh" iconCls="icon-reload" onclick="reloadTransOrder()"/>
			</div>
		</div>
	</div>
</div>